(ns demo.handler
  (:require [compojure.core :refer :all]
            [compojure.route :as route]
            [ring.middleware.defaults :refer [wrap-defaults site-defaults]]
            [ring.middleware.anti-forgery :refer :all]
            [ring.middleware.session.cookie :refer (cookie-store)]
            [demo.core :as dc]))


(defn get-custom-token [request]
  (get-in request [:headers "x-forgery-token"]))

(defroutes app-routes
  (GET "/" [] "Hello, Wrold!")
  (GET "/get/goods/index/:id" [id] (dc/get-label-route id))
  (GET "/get/contain" [applicant sku] (dc/redis-cmd applicant sku))
  (POST "/get/goods/sql" [activity applicant] (dc/query-goods activity applicant))
  (GET "/get/sql/:baseid" [baseid] (dc/get-all-sql baseid))
  (GET "/get/calcu/date" [] (dc/get-all-calcu-date))
  (route/not-found "Not Found"))

(def app
  (-> app-routes
   (wrap-defaults (assoc site-defaults :security false))))

